package com.karolak.stock.oscilator;

import com.karolak.stock.data.DataManager;
import com.karolak.stock.indicator.HighTrInd;
import com.karolak.stock.indicator.Indicator;
import com.karolak.stock.indicator.LowTrInd;

public class LossOsc extends Oscilator {

	private HighTrInd highTrInd;

	public LossOsc(DataManager dataManager, int period, LowTrInd lowTrInd, HighTrInd highTrInd) {
		super(dataManager, period, lowTrInd);
		this.highTrInd = highTrInd;
		setName(String.format("LossOsc"));
	}

	@Override
	public double execute(double x) {
		double low = getDataManager().getLast(getLowTrInd().getName());
		double high = getDataManager().getLast(getHighTrInd().getName());
		
		double pos = getDataManager().getLast("Position");
		double loss = 0;
		if (pos > 0) {
			loss = x - high;
		} else if (pos < 0) {
			loss = x - low;
		}
		return loss;
	}

	public Indicator getLowTrInd() {
		return super.getInput();
	}

	protected HighTrInd getHighTrInd() {
		return highTrInd;
	}
}